<?php
mysql_select_db($database_konek, $konek);
$query_plugtext2 = "SELECT * FROM galleryplug_data WHERE id_module = $_GET[id] ";
$plugtext2 = mysql_query($query_plugtext2, $konek) or die(mysql_error());
$row_plugtext2 = mysql_fetch_assoc($plugtext2);
$totalRows_plugtext2 = mysql_num_rows($plugtext2);

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("UPDATE galleryplug SET judul=%s, width=%s, height=%s, perpage=%s WHERE id=%s ",
                       GetSQLValueString($_POST['judul'], "text"),
                       GetSQLValueString($_POST['width'], "int"),
					   GetSQLValueString($_POST['height'], "int"),
					   GetSQLValueString($_POST['perpage'], "int"),
                       GetSQLValueString($_POST['id'], "int"));
if ($totalRows_plugtext2>0){
include("resize-class.php");
do  {

// *** 1) Initialise / load image
	$resizeObj = new resize('../g-konten/fm/gallery/'.$_GET['id'].'/' . $row_plugtext2['image']);

	// *** 2) Resize image (options: exact, portrait, landscape, auto, crop)
	$resizeObj -> resizeImage($_POST['width'], $_POST['height'], 'crop');

	// *** 3) Save image
	$resizeObj -> saveImage('../g-konten/fm/gallery/'.$_GET['id'].'/thumb/' . $row_plugtext2['image'], 100);

} while ($row_plugtext2 = mysql_fetch_assoc($plugtext2));
}

  mysql_select_db($database_konek, $konek);
  $Result1 = mysql_query($insertSQL, $konek) or die(mysql_error());

   ?>
	
	 <script language="javascript">
  	<!--
     	    alert('Edit Success')
			window.location = "home.php?page=pluginview&p=<?php echo $_GET['p'] ?>&root=add_module.php";
			
   	--></script>
	<?php
}

$colname_admin = "-1";
if (isset($_SESSION['MM_Username'])) {
  $colname_admin = $_SESSION['MM_Username'];
}
mysql_select_db($database_konek, $konek);
$query_admin = sprintf("SELECT * FROM data_user WHERE nama_user = %s", GetSQLValueString($colname_admin, "text"));
$admin = mysql_query($query_admin, $konek) or die(mysql_error());
$row_admin = mysql_fetch_assoc($admin);
$totalRows_admin = mysql_num_rows($admin);

mysql_select_db($database_konek, $konek);
$query_plugtext = "SELECT * FROM galleryplug WHERE id = $_GET[id] ";
$plugtext = mysql_query($query_plugtext, $konek) or die(mysql_error());
$row_plugtext = mysql_fetch_assoc($plugtext);
$totalRows_plugtext = mysql_num_rows($plugtext);

?>

  <form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
    <table width="100%" align="center">
      <tr valign="baseline">
        <td width="12%" align="left" valign="top" nowrap="nowrap"><strong>Judul:</strong></td>
        <td width="88%"><input type="text" name="judul" class="form-control" value="<?php echo $row_plugtext['judul']; ?>" size="32" /></td>
      </tr>
      <tr valign="baseline">
        <td align="left" valign="top" nowrap="nowrap"><strong>width:</strong></td>
        <td><input name="width" type="text" class="form-control" value="<?php echo $row_plugtext['width']; ?>" size="32" /></td>
      </tr>
      <tr valign="baseline">
        <td align="left" valign="top" nowrap="nowrap"><strong>height:</strong></td>
        <td><input name="height" type="text" class="form-control" value="<?php echo $row_plugtext['height']; ?>" size="32" /></td>
      </tr>
      <tr valign="baseline">
        <td align="left" valign="top" nowrap="nowrap"><strong>Total Perpage : </strong></td>
        <td><input name="perpage" type="text" class="form-control" value="<?php echo $row_plugtext['perpage']; ?>" size="32" /></td>
      </tr>
      <tr valign="baseline">
        <td align="left" valign="top" nowrap="nowrap">&nbsp;</td>
        <td><input type="submit" value="Submit" id="status-update-btn" class="btn btn-primary pull-right" /></td>
      </tr>
    </table>
    <input type="hidden" name="id" value="<?php echo $row_plugtext['id']; ?>" />
    <input type="hidden" name="MM_insert" value="form1" />
</form>
 
<?php

mysql_free_result($plugtext);
?>
